using System;
using System.Data.Entity.ModelConfiguration;
using System.Data.Common;
using System.Data.Entity;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using HISModels.Entities;

namespace HISModels.Mapping
{
	public class PatientRegMap : EntityTypeConfiguration<PatientReg>
	{
		public PatientRegMap()
		{
			// Primary Key
			this.HasKey(t => t.Id);

			// Properties
			this.Property(t => t.CodeValue)
				.IsRequired()
				.HasMaxLength(50);
				
			this.Property(t => t.CreatedBy)
				.HasMaxLength(50);
				
			this.Property(t => t.ModifiedBy)
				.HasMaxLength(50);
				
			// Table & Column Mappings
			this.ToTable("PatientRegs");
			this.Property(t => t.Id).HasColumnName("Id");
			this.Property(t => t.CodeValue).HasColumnName("CodeValue");
			this.Property(t => t.HuLobRelId).HasColumnName("HuLobRelId");
			this.Property(t => t.RegistrationTime).HasColumnName("RegistrationTime");
			this.Property(t => t.PatientId).HasColumnName("PatientId");
			this.Property(t => t.CreatedBy).HasColumnName("CreatedBy");
			this.Property(t => t.CreatedOn).HasColumnName("CreatedOn");
			this.Property(t => t.ModifiedBy).HasColumnName("ModifiedBy");
			this.Property(t => t.ModifiedOn).HasColumnName("ModifiedOn");
			this.Property(t => t.RecordStatus).HasColumnName("RecordStatus");

			// Relationships
			this.HasRequired(t => t.HuLobRel)
				.WithMany(t => t.PatientRegs)
				.HasForeignKey(d => d.HuLobRelId);
				
			this.HasRequired(t => t.Patient)
				.WithMany(t => t.PatientRegs)
				.HasForeignKey(d => d.PatientId);
				
		}
	}
}

